package com.example.pathprotectsystem.mapper;

import com.example.pathprotectsystem.pojo.BindModel;
import com.example.pathprotectsystem.pojo.SheetModel;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;   

@Mapper
public interface ResultMapper {
    @Select("select * from task " +
            "join path on task.pathId = path.id " +
            "join user on task.userId = user.id " +
            "where task.userId = #{id} and (task.taskName like concat('%',concat(#{str},'%')) or " +
            "task.taskType like concat('%',concat(#{str},'%')) or " +
            "task.taskTime like concat('%',concat(#{str},'%')) or " +
            "user.userName like concat('%',concat(#{str},'%')) or " +
            "user.userType like concat('%',concat(#{str},'%')) or " +
            "path.pathName like concat('%',concat(#{str},'%')) or " +
            "path.pavementType like concat('%',concat(#{str},'%')) or " +
            "task.status like concat('%',concat(#{str},'%'))) " +
            "order by task.taskTime desc"
    )
    List<BindModel> usertasklist(String str, int id);

    @Insert("insert into daycheck(finishTime, taskId, damageType, damageDescribe, comment)" +
            "values(now(),#{id},#{damageType},#{damageDescribe},#{comment})")
    void addf1(SheetModel sheetModel);

    @Insert("insert into facilitydamage(finishTime, damagePart, damageReason, facilityName, suggest, taskId)" +
            "values(now(),#{damagePart},#{damageReason},#{facilityName},#{suggest},#{id})")
    void addf2(SheetModel sheetModel);
    @Insert("insert into pavementflat(finishTime, taskId, iri, comment)" +
            "values(now(),#{id},#{iri},#{comment})")
    void addf3(SheetModel sheetModel);
    @Insert("insert into pavementdamage(finishTime, taskId, allLongth, allWidth, damageType, " +
            "damageLongth, damageWidth, damageHighth, damageDescribe, damageArea, comment)" +
            "values(now(),#{id},#{allLongth},#{allWidth},#{damageType},#{damageLongth}," +
            "#{damageWidth},#{damageHighth},#{damageDescribe},#{damageArea},#{comment})")
    void addf4(SheetModel sheetModel);
}
